package cn.wolfcode.web.interceptors;

import cn.wolfcode.domain.Employee;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CheckLoginInterceptor implements HandlerInterceptor{

    //配置前置拦截器
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        //获取保存在作用域的session
        Employee employee = (Employee) request.getSession().getAttribute("USER_IN_SESSION");
        //如果获得的employee不为空，就放行，如果为空，重定向会登陆页面
        if(employee==null){
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
